<template>
  <div>
    <!-- 商品品牌 -->
    <el-radio-group v-model="activeName" style="margin-bottom: 10px;">
      <el-radio-button label="brand">品牌列表</el-radio-button>
      <el-radio-button label="custom">自定义品牌列表</el-radio-button>
    </el-radio-group>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <!-- 品牌列表 -->
      <el-tab-pane name="brand">
        <!-- 搜索 -->
        <el-row :gutter="20">
          <el-col :span="5">
            <el-input v-model="brandName" placeholder="品牌名称"></el-input>
          </el-col>
          <el-col :span="4">
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="brand_search"
              >搜索</el-button
            >
          </el-col>
        </el-row>
        <!-- 申请按钮 -->
        <el-row :gutter="20" style="margin:20px 0">
          <el-col :span="3">
            <el-button
              style="width:100%; margin-left:-10px"
              type="primary"
              icon="el-icon-plus"
              @click="apply_brand = true"
              >申请品牌</el-button
            >
          </el-col>

          <!-- 隐藏框 -->
          <el-dialog title="申请品牌" :visible.sync="apply_brand">
            <el-form :model="form" :rules="rules">
              <el-form-item label="申请品牌" label-width="120px" prop="value">
                <el-select
                  v-model="form.value"
                  placeholder="请选择"
                  @change="pull_down($event)"
                >
                  <el-option
                    v-for="item in form.options"
                    :key="item.label"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="预览品牌图片" label-width="120px">
                <el-image :src="form.img"></el-image>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="apply_brand = false">取 消</el-button>
              <el-button type="primary" @click="Appbrand">确 定</el-button>
            </div>
          </el-dialog>

          <el-col :span="3">
            <el-button
              style="width:100%; margin-left:-10px"
              type="danger"
              icon="el-icon-delete"
              @click="AllDel"
              >批量删除</el-button
            >
          </el-col>
        </el-row>

        <!-- 表单展示 -->

        <el-table
          border
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          width="100%"
          @selection-change="handleSelectionChange"
          style="font-size: 14px"
          :row-style="{ height: '20px' }"
          :cell-style="{ padding: '0px' }"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column label="品牌名字" min-width="20%">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column label="品牌LOGO" min-width="20%">
            <template slot-scope="scope">
              <el-image
                style="width: 60px; height: 60px"
                :src="scope.row.url"
                fit="cover"
              ></el-image>
            </template>
          </el-table-column>
          <el-table-column label="状态" show-overflow-tooltip min-width="20%">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.province === '审核通过' ? 'success' : 'warning'
                "
                disable-transitions
                >{{ scope.row.province }}</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column prop="address" label="拒绝原因" min-width="20%">
          </el-table-column>
          <el-table-column label="操作" show-overflow-tooltip min-width="20%">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, tableData)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          style="margin:20px 0"
          @size-change="brandSizeChange"
          @current-change="brandCurrentChange"
          :current-page="brand_currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="2"
          layout="total, sizes, prev, pager, next, jumper"
          :total="400"
        >
        </el-pagination>
      </el-tab-pane>

      <!-- 自定义品牌列表 -->
      <el-tab-pane name="custom">
        <!-- 搜索 -->
        <el-row :gutter="20">
          <el-col :span="5">
            <el-input
              v-model="custom_brandName"
              placeholder="品牌名称"
            ></el-input>
          </el-col>
          <el-col :span="4">
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="custom_brand_search"
              >搜索</el-button
            >
          </el-col>
        </el-row>

        <!-- 申请按钮 -->
        <el-row :gutter="20" style="margin:20px 0">
          <el-col :span="4">
            <el-button
              style="width:100%; margin-left:-10px"
              type="primary"
              icon="el-icon-plus"
              @click="custom_apply_brand = true"
              >申请自定义品牌</el-button
            >
          </el-col>

          <!-- 隐藏框 -->
          <el-dialog title="申请自定义品牌" :visible.sync="custom_apply_brand">
            <el-form
              :model="custom_form"
              :rules="custom_rules"
              ref="custom_form"
              class="demo-ruleForm"
            >
              <el-form-item label="申请品牌" label-width="120px" prop="value">
                <el-input v-model="custom_form.value"></el-input>
              </el-form-item>

              <el-form-item
                label="品牌LOGO"
                label-width="120px"
                prop="custom_imageUrl"
              >
                <el-upload
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-success="custom_Success"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                >
                  <img
                    v-if="custom_form.custom_imageUrl"
                    :src="custom_form.custom_imageUrl"
                    class="avatar"
                  />

                  <i v-else class="el-icon-plus"></i>
                </el-upload>
              </el-form-item>

              <el-form-item
                label="品牌证书"
                label-width="120px"
                prop="brand_imageUrl"
              >
                <el-upload
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-success="brand_Success"
                  :on-preview="brand_PictureCardPreview"
                  :on-remove="brandRemove"
                >
                  <img
                    v-if="custom_form.brand_imageUrl"
                    :src="custom_form.brand_imageUrl"
                    class="avatar"
                  />

                  <i v-else class="el-icon-plus"></i>
                </el-upload>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="custom_apply_brand = false">取 消</el-button>
              <el-button type="primary" @click="custom_Appbrand('custom_form')"
                >确 定</el-button
              >
            </div>
          </el-dialog>

          <el-col :span="3">
            <el-button
              style="width:100%; margin-left:-10px"
              type="danger"
              icon="el-icon-delete"
              @click="custom_AllDel"
              >批量删除</el-button
            >
          </el-col>

          <!-- 自定义表单展示 -->

          <el-table
            border
            ref="multipleTable"
            :data="custom_tableData"
            tooltip-effect="dark"
            width="100%"
            @selection-change="custom_SelectionChange"
            style="font-size: 14px"
            :row-style="{ height: '20px' }"
            :cell-style="{ padding: '0px' }"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column label="品牌名字" min-width="20%">
              <template slot-scope="scope">{{ scope.row.date }}</template>
            </el-table-column>
            <el-table-column label="品牌LOGO" min-width="20%">
              <template slot-scope="scope">
                <el-image
                  style="width: 60px; height: 60px"
                  :src="scope.row.url"
                  fit="cover"
                ></el-image>
              </template>
            </el-table-column>
            <el-table-column
              label="品牌证书"
              show-overflow-tooltip
              min-width="20%"
            >
              <template slot-scope="scope">
                <el-image
                  style="width: 60px; height: 60px"
                  :src="scope.row.url"
                  fit="cover"
                ></el-image>
              </template>
            </el-table-column>
            <el-table-column label="状态" min-width="20%">
              <template slot-scope="scope">
                <el-tag
                  :type="
                    scope.row.province === '审核通过' ? 'success' : 'warning'
                  "
                  disable-transitions
                  >{{ scope.row.province }}</el-tag
                >
              </template>
            </el-table-column>

            <el-table-column prop="address" label="拒绝原因" min-width="20%">
            </el-table-column>
            <el-table-column label="操作" show-overflow-tooltip min-width="20%">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click="custom_Delete(scope.$index, tableData)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <!-- 自定义分页 -->
          <el-pagination
            style="margin:20px 0"
            @size-change="custom_SizeChange"
            @current-change="custom_CurrentChange"
            :current-page="custom_currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="2"
            layout="total, sizes, prev, pager, next, jumper"
            :total="400"
          >
          </el-pagination>
        </el-row>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: "",
  props: [""],
  data() {
    return {
      activeName: "brand",
      brandName: "",
      // 点击打开申请品牌隐藏框
      apply_brand: false,
      // 品牌表单内容
      form: {
        name: "",
        region: "",
        options: [
          {
            value: {
              value: "美图",
              label: "美图",
              img: "https://images.lecshop.cn/20200419/1587273898270.jpg",
            },
            label: "美图",
            img: "https://images.lecshop.cn/20200419/1587273898270.jpg",
          },
          {
            value: {
              value: "小米",
              label: "小米",
              img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
            },
            label: "小米",
            img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
          },
          {
            value: {
              value: "苹果",
              label: "苹果",
              img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
            },
            label: "苹果",
            img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
          },
          {
            value: {
              value: "三星",
              label: "三星",
              img: "https://images.lecshop.cn/20200419/1587273950982.jpg",
            },
            label: "三星",
            img: "https://images.lecshop.cn/20200419/1587273950982.jpg",
          },
          {
            value: {
              value: "TCL",
              label: "TCL",
              img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
            },
            label: "TCL",
            img: "https://images.lecshop.cn/20200419/1587273931813.jpg",
          },
        ],
        value: "",
        // 图片
        img: "",
      },
      // 验证
      rules: {
        value: [
          {
            type: "string",
            required: true,
            message: "请选择品牌",
            trigger: "change",
          },
        ],
      },
      // 表单数据
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "审核通过",
          city: "普陀区",
          address: "无",
          zip: false,
          zhuangtai: "上架",
          shenhe: "审核通过",
          jiaqian: 999,
          pin: "小米",
          url:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "不通过",
          city: "普陀区",
          address: "无",
          zip: true,
          zhuangtai: "上架",
          shenhe: "审核通过",
          jiaqian: 999,
          pin: "小米",
          url: "无",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "wu",
          zip: true,
          zhuangtai: "上架",
          shenhe: "审核通过",
          jiaqian: 999,
          pin: "小米",
          url: "无",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "无",
          zip: true,
          zhuangtai: "上架",
          shenhe: "不通过",
          jiaqian: 999,
          pin: "小米",
          url:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
        },
      ],
      // 品牌当前分页页码
      brand_currentPage: 1,

      // 自定义品牌
      custom_brandName: "",
      // 自定义表单内容
      custom_form: {
        value: "",
        custom_imageUrl: "",
        brand_imageUrl: "",
      },
      // 自定义表单验证内容
      custom_rules: {
        value: [
          { required: true, message: "请输入自定义品牌", trigger: "blur" },
          {
            min: 3,
            max: 20,
            message: "长度在 3 到 20 个字符",
            trigger: "blur",
          },
        ],
        custom_imageUrl: [
          {
            type: "date",
            required: true,
            message: "请插入图片",
            trigger: "change",
          },
        ],
        brand_imageUrl: [
          {
            type: "date",
            required: true,
            message: "请插入图片",
            trigger: "change",
          },
        ],
      },
      // 点开自定义品牌隐藏
      custom_apply_brand: false,
      // 表单数据
      custom_tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "审核通过",
          city: "普陀区",
          address: "无",
          zip: false,
          zhuangtai: "上架",
          shenhe: "审核通过",
          jiaqian: 999,
          pin: "小米",
          url:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "不通过",
          city: "普陀区",
          address: "无",
          zip: true,
          zhuangtai: "上架",
          shenhe: "审核通过",
          jiaqian: 999,
          pin: "小米",
          url: "无",
        },
      ],
      // 自定义分页页数
      custom_currentPage:1,
    };
  },

  components: {},

  computed: {},

  beforeMount() {},

  mounted() {},

  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 品牌搜索按钮
    brand_search() {},
    // 批量删除
    AllDel() {},
    // 申请品牌数据监听
    pull_down(event) {
      // console.log(event);
      this.form.value = event.value;
      this.form.img = event.img;
    },
    // 确认提交申请信息
    Appbrand() {
      this.apply_brand = false;
    },
    // 表单事件
    handleSelectionChange(val) {
      console.log(val);
    },
    // 表单中删除按钮
    handleDelete(index, row) {
      // console.log(index, row);

      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row.splice(index, 1);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 品牌分页
    brandSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    brandCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },

    // 自定义品牌
    // 搜索按钮
    custom_brand_search() {},

    // 自定义品牌确认提交信息
    custom_Appbrand(formName) {
      // this.custom_apply_brand = false;
      // console.log(this.$refs[formName].validate);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return (this.custom_apply_brand = true);
        }
      });
    },
    // 自定义批量删除
    custom_AllDel() {},
    // 自定义上传图片
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      console.log(file);
    },
    // 自定义上传LOGO成功回调
    custom_Success(res, file) {
      console.log(res, 999);
    },
    // 品牌证书
    brand_Success(res, file) {
      console.log(res, 999);
    },
    brand_PictureCardPreview(file) {},
    brandRemove(file, fileList) {},

    // 自定义表单监听事件
    custom_SelectionChange(val) {},
    // 自定义表单删除
    custom_Delete(index, row) {},

    // 自定义分页
    custom_SizeChange(val){
       console.log(`每页 ${val} 条`);
    },
    custom_CurrentChange(val){
        console.log(`当前页: ${val}`);
    },
  },

  watch: {},
};
</script>
<style lang="scss" scoped></style>
